from rest_framework import serializers
from common.models import User
from .models import ShippingContainer, Task


class ShippingContainerSerializer(serializers.ModelSerializer):
    class Meta:
        model = ShippingContainer
        fields = '__all__'


class TaskSerializer(serializers.ModelSerializer):

    creator = serializers.PrimaryKeyRelatedField(
        queryset=User.objects.all()
    )

    class Meta:
        model = Task
        fields = '__all__'
        # 以下属性不可改/写
        read_only_fields = [
            'status',
            'result_dataset',
            'created_at',
            'submitted_at',
            'finished_at',
        ]
        # 以下属性在创建/更改任务的时候，是可选的
        extra_kwargs = {
            'config': {'required': False},
            'input_dataset': {'required': False},
        }

